package com.yunfeisoft.business.dao.impl;

import com.yunfeisoft.base.model.User;
import com.yunfeisoft.base.model.WorkflowInstance;
import com.yunfeisoft.business.dao.inter.AskLeaveApprovalDao;
import com.yunfeisoft.business.model.AskLeaveApproval;
import com.yunfeisoft.common.base.BaseDaoImpl;
import com.yunfeisoft.common.sql.builder.SelectBuilder;
import com.yunfeisoft.common.sql.builder.WhereBuilder;
import com.yunfeisoft.common.utils.Page;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * ClassName: AskLeaveApprovalDaoImpl
 * Description: 请假审批表Dao实现
 * Author: Jackie liu
 * Date: 2020-05-14
 */
@Repository
public class AskLeaveApprovalDaoImpl extends BaseDaoImpl<AskLeaveApproval, String> implements AskLeaveApprovalDao {

    @Override
    public Page<AskLeaveApproval> queryPage(Map<String, Object> params) {
        WhereBuilder wb = new WhereBuilder();
        wb.setOrderByWithDesc("al.createTime");
        if (params != null) {
            initPageParam(wb, params);
            wb.andFullLike("u.name", params.get("createName"));
        }

        SelectBuilder builder = getSelectBuilder("al");
        builder.column("u.name as createName")
                .column("wi.status as validStatus")
                .join(User.class).alias("u").on("al.createId = u.id").build()
                .join(WorkflowInstance.class).alias("wi").on("wi.formId = al.id").build();

        return queryPage(builder.getSql(), wb);
    }
}